package com.cll.prototype.mongodb.spring;

import com.cll.prototype.mongodb.spring.dao.ResumePreviewDao;
import com.cll.prototype.mongodb.spring.bean.ResumePreview;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/11/29 14:34
 */
public class MongoDemo {

    public static void main(String[] args) {
//        insertTest();
        findByName();
    }

    public static void insertTest() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
        ResumePreviewDao bean = context.getBean(ResumePreviewDao.class);

        ResumePreview resumePreview = new ResumePreview();
        // 如果设置ID，就使用这个ID，如果没有设置，就会自动生成
//        resumePreview.setId("aaaaaaaaaaaaaaaaaaa");
        resumePreview.setCity("郑州");
        resumePreview.setName("苏志飞");
        // 注意时间会和本地时间相差8个小时
        LocalDateTime of = LocalDateTime.of(1992, 1, 2, 8, 0, 0);
        Date birthday = Date.from(of.atZone(ZoneId.systemDefault()).toInstant());
        resumePreview.setBirthday(birthday);
        resumePreview.setGender(0);
        resumePreview.setExpectSalary(9000D);
        bean.insertResumePreview(resumePreview);
    }

    public static void findByName() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring-context.xml");
        ResumePreviewDao resumePreviewDao = context.getBean(ResumePreviewDao.class);
        ResumePreview byName = resumePreviewDao.findByName("苏志飞");
        System.out.println(byName.toString());

        ResumePreview daoByName = resumePreviewDao.findByName("王楠", 15000D);
        System.out.println(daoByName.toString());
    }

}